package cn.tedu.four.config;

import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.HibernateValidator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.validation.Validation;
import javax.validation.Validator;

/**
 * ClassName: ValidationConfiguration
 * Package: cn.tedu.four.config
 * Description:
 *
 * @Author: @Albert
 * @Version: 1.0
 */
@Configuration
@Slf4j
public class ValidationConfiguration {
    public ValidationConfiguration() {
        log.info("构建validator工厂配置类");
    }

    @Bean
    public Validator validator(){
        return Validation.byProvider(HibernateValidator.class)
                .configure()   //开始配置
                .failFast(true)
                .buildValidatorFactory()  //构建validator工厂
                .getValidator();
    }
}
